package Commands;

import domain.Subject;

import domain.Controller;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class CmdSaveSubject extends Command
  {
    protected String nextJspUrl = 
      "userStory1.jsp"; 
    CommandFactory comFac;
    Controller controller;

    public void init(CommandFactory comFac, Controller c)
      throws ServletException 
    {
      this.comFac = comFac;
      this.controller = c;
    }

    public void execute(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException 
    {
      long id = 0L;
      String title = req.getParameter("valgfagsTitle");
      String beskrivelse = req.getParameter("valgfagsBeskrivelse");
      //String underviser = req.getParameter("underviser");
      Subject subject = new Subject();
      if (!req.getParameter("valgfagsTitle").equals("")&&req.getParameter("valgfagsTitle")!=null&&req.getParameter("saveValgfag")!=null)
      {
        subject.setId(id);
        subject.setTitle(title);
        subject.setBeskrivelse(beskrivelse);
        //subject.setUnderviser(underviser);
        controller.saveSubject(subject);
        req.setAttribute("status", "Valgfaget oprettet");
      }
      else
        req.setAttribute("status", "Fejl i indtastningen");
    }
    
    public String getNextJspUrl()
    {
      return nextJspUrl;
    }
  }



  